package com.zx.notification.common.mapstruct;

import com.zx.core.enums.StatusEnum;
import com.zx.notification.common.enums.ChannelTypeEnum;
import com.zx.notification.common.enums.MqTypeEnum;
import com.zx.notification.common.enums.PushStrategyEnum;
import com.zx.notification.common.model.NotificationChannelsConfig;
import com.zx.notification.common.param.NotificationChannelsConfigParam;
import com.zx.notification.common.vo.NotificationChannelsConfigVO;
import org.mapstruct.AfterMapping;
import org.mapstruct.Mapper;
import org.mapstruct.MappingTarget;
import org.mapstruct.ReportingPolicy;

/**
 * <p>
 * description: 通知渠道配置映射器 <br>
 * create: 2025-10-15
 * </p>
 *
 * @author zhou  xun
 */
@Mapper(componentModel = "spring", unmappedTargetPolicy = ReportingPolicy.IGNORE)
public interface NotificationChannelsConfigMapStructMapper {

    /**
     * 将NotificationChannelsConfigParam转换为NotificationChannelsConfig实体
     *
     * @param notificationChannelsConfigParam 通知渠道配置参数
     * @return NotificationChannelsConfig实体
     */
    NotificationChannelsConfig notificationChannelsConfigParamToNotificationChannelsConfig(NotificationChannelsConfigParam notificationChannelsConfigParam);

    /**
     * 将NotificationChannelsConfig实体转换为NotificationChannelsConfigVO视图对象
     *
     * @param notificationChannelsConfig 通知渠道配置实体
     * @return NotificationChannelsConfigVO视图对象
     */
    NotificationChannelsConfigVO notificationChannelsConfigToNotificationChannelsConfigVO(NotificationChannelsConfig notificationChannelsConfig);

    /**
     * 在映射完成后，设置描述性字段
     *
     * @param notificationChannelsConfig   通知渠道配置实体
     * @param notificationChannelsConfigVO 通知渠道配置VO
     */
    @AfterMapping
    default void setDescriptions(NotificationChannelsConfig notificationChannelsConfig, @MappingTarget NotificationChannelsConfigVO notificationChannelsConfigVO) {
        // 设置渠道类型描述
        ChannelTypeEnum channelTypeEnum = ChannelTypeEnum.getEnumByCode(notificationChannelsConfig.getChannelType());
        if (channelTypeEnum != null) {
            notificationChannelsConfigVO.setChannelTypeDesc(channelTypeEnum.getDesc());
        }

        // 设置消息队列类型描述
        MqTypeEnum mqTypeEnum = MqTypeEnum.getEnumByCode(notificationChannelsConfig.getMqType());
        if (mqTypeEnum != null) {
            notificationChannelsConfigVO.setMqTypeDesc(mqTypeEnum.getDesc());
        }

        // 设置推送策略描述
        PushStrategyEnum pushStrategyEnum = PushStrategyEnum.getEnumByCode(notificationChannelsConfig.getPushStrategy());
        if (pushStrategyEnum != null) {
            notificationChannelsConfigVO.setPushStrategyDesc(pushStrategyEnum.getDesc());
        }

        // 设置状态描述
        StatusEnum statusEnum = StatusEnum.getEnumByCode(notificationChannelsConfig.getStatus());
        if (statusEnum != null) {
            notificationChannelsConfigVO.setStatusDesc(statusEnum.getDesc());
        }
    }
}